/*	
 * Authors: Ken YANG <spng.yang@gmail.com>
 * 	
 * Mammoth client main program
 *
 * Copyright (C) 2007-2008 Ken YANG
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation, version 2. 
 * THIS SOFTWARE COMES "AS IS" WITHOUT ANY WARRANTIES.
 */

#if !defined (_HAVE_EFFECTIVE_IO_H)
#define _HAVE_EFFECTIVE_IO_H 1

#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include "error.h"

#define MAXLINE 4096	/* max text line length */


/* Continue to read, if had not got required data */
ssize_t keep_read(int fd, void *buf, size_t count);
ssize_t Keep_read(int fd, void *buf, size_t count);

/* Continue to write, if didn't write enough data */
void Keep_write(int fd, const void *buf, size_t count);

/* 
 * Read a Line. For performance, use buffer. However 
 * for avoiding the problem incurred by standard I/O, 
 * we use own buffer to make caller check the status 
 * of the buffer.
 *
 * */
ssize_t readline(int fd, void *ptr, size_t maxlen);

/* reentrant version of readline */
ssize_t readline_r(int fd, void *ptr, size_t maxlen);

/* Above wrapper */
ssize_t Readline(int fd, void *ptr, size_t maxlen);

/* Check the status of buffer */
ssize_t readlinebuf(void *vptr);

/* UNIX I/O wrapper, including error handle */
ssize_t Read(int fd, void *buf, size_t count);
void Write(int fd, void *buf, size_t count);

/* Standard I/O wrapper, including error handle */
char *Fgets(char *s, int size, FILE *stream);
void Fputs(const char *s, FILE *stream);

#endif

